How to Run Two Tasks in Two Terminals Side by Side in VS Code using tasks.json

Share

In VS Code, it's possible to create a build task (or test task) to run two tasks in two terminals side by side using tasks.json. An example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build-typescript-and-sass",
            "detail": "Runs Typescript and Sass compilers.",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn": [
                "build-typescript",
                "build-sass"
            ],
            "dependsOrder": "parallel"
        },
        {
            "label": "build-typescript",
            "type": "shell",
            "command": "npx tsc",
            "presentation": {
                "group": "my-build-group"
            }
        },
        {
            "label": "build-sass",
            "type": "npm",
            "script": "build-sass-using-grunt",
            "presentation": {
                "group": "my-build-group"
            }
        }
    ]
}

The result:

VS Code's main window, with two tasks running in two terminals side by side at the bottom of the window.
Two tasks running side by side in VS Code.

Understanding The Code

Most of this code was explained in a previous tutorial—[How to Run Two Tasks in Parallel in VS Code using tasks.json]—so we'll focus on the unique parts.

The explorer sidebar of VS Code showing a folder .vscode and in it tasks.json.
Where the tasks.json file is located in VS Code.

When a task has a presentation key containing group key, this "presentation group" is used by VS Code to group terminals together in its GUI. We can write anything we want as its value. In my case, I wrote my-build-group, so all tasks with this value for presentation group will be grouped together and appear side by side.

Note that the group in presentation of a task isn't the same thing as the root group key of a task. The root group key is used to tell VS Code what kind of task it is (e.g. a build task), and whether it's the default build task or not. We need to use group inside presentation for it to have the effect we want.

Documentation

group: Controls whether the task is executed in a specific terminal group using split panes. Tasks in the same group (specified by a string value) will use split terminals to present instead of a new terminal panel.

https://code.visualstudio.com/docs/editor/tasks#_output-behavior (accessed 2024-11-22)
Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments (2)